<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增库存表')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-stock-add">

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">货位编码：</label>
                <div class="col-sm-8">
                    <input name="cargoSpaceId" id="cargoSpaceId" class="form-control" type="text" readonly required>
                    <input name="warehouseId" id="warehouseId" class="form-control" type="text" readonly required>
                    <a id="selectCargo" class="btn btn-success" onclick="selectCargo()" >
                        ...
                    </a>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">物品编码：</label>
                <div class="col-sm-8">
                    <input name="productId" id="productId" class="form-control" type="text" readonly required>
                    <a id="selectProduct" class="btn btn-success" onclick="selectProduct()" >
                        ...
                    </a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">批号：</label>
                <div class="col-sm-8">
                    <input name="lotNo" id="lotNo" class="form-control" type="text"  required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">物品状态：</label>
                <div class="col-sm-8">
                    <select name="productStatus"  class="form-control" th:with="type=${@dict.getType('product_status')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                th:value="${dict.dictValue}" ></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">库存数量：</label>
                <div class="col-sm-8">
                    <input name="quantity" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">托盘条码：</label>
                <div class="col-sm-8">
                    <input name="trayCode" class="form-control" type="text" required>
                </div>
            </div>


        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "stock/stock"
        $("#form-stock-add").validate({
            focusCleanup: true
        });

        function submitHandler() {

                if ($.validate.form()) {
                    $.operate.save(prefix + "/add", $('#form-stock-add').serialize());
                }
        }

        function selectCargo(){
            var options = {
                title: '选择货位信息',
                url: "/stock/stock/selectCargo",
                callBack: callbackCargo
            };
            $.modal.openOptions(options);
        }

        function callbackCargo(index, layero){
            var orders = [];
            var obj = {};
            var row = $("#bootstrap-table").bootstrapTable('getSelections');
            var Members = layero.find("iframe")[0].contentWindow.result();
            if (Members.length == 0) {
                $.modal.alertWarning("请选择一条记录");
                return;
            }
            console.log("member",Members)
            console.log("row",row[0]);
            $("#cargoSpaceId").val(Members[0].cargoSpaceId)
            $("#warehouseId").val(Members[0].warehouseId)

            $.modal.close(index);
            $.modal.closeLoading();

        }

        //选择物资
        function selectProduct() {
            var options = {
                title: '选择物品信息',
                url: "/in/stockin/selectPro",
                callBack: getMembers
            };
            $.modal.openOptions(options);

        }

        function getMembers(index, layero){
            var orders = [];
            var obj = {};
            var row = $("#bootstrap-table").bootstrapTable('getSelections');
            var Members = layero.find("iframe")[0].contentWindow.submitHandler();
            if (Members.length == 0) {
                $.modal.alertWarning("请选择一条记录");
                return;
            }
            console.log("member",Members)
            console.log("row",row[0]);


            $("#productId").val(Members[0].productId)


            $.modal.close(index);
            $.modal.closeLoading();

        }


    </script>
</body>
</html>